home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000093_icon-group-sender _Thu Apr 8 16:28:46 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
1KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA22603
for icon-group-addresses; Thu, 8 Apr 1999 16:27:34 -0700 (MST)
Message-Id: <199904082327.QAA22603@baskerville.CS.Arizona.EDU>
To: icon-group@optima.CS.Arizona.EDU
Date: Thu, 08 Apr 1999 17:35:22 -0400
From: "Hudon, Christian (EXCHANGE:MTL:6X16)" <chudon@americasm01.nt.com>
Subject: Deep copy in Icon?
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Hi,
could someone tell me what's wrong with the following snippet of Icon
code?
procedure deepcopy(x, t)
/t := table()
case type(x) of {
"list"|"table"|"set"|"record" : {
e := t[image(x)]
if /e then {
e := copy(x)
t[image(x)] := e
every sub := !e do sub := deepcopy(sub, t)
}
return e
}
default: return x
}
end
(This is supposed to do a deep copy of an arbitrary object, preserving
the structure.)
I thought you could assign to the elements of a set, list, etc. with
something like
every e := !l do e := foo(e)
but it doesn't seem to work here... when I do deepcopy([1, [2, 3], 4]),
the list that's returned still has the inner list [2, 3] shared.
If there's a more Icon-ish way to do all this, I'm also appreciate
hearing about it.
Thanks,
Christian